<%@ page pageEncoding="utf-8" %>
<%@include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<fmt:bundle basename="res">
<head>
    <meta charset="utf-8">
    <title><fmt:message key='zthd'/></title>
    <jsp:include page="/WEB-INF/commons/commons-header.jsp" flush="true"/>
    <style>
        html {
            background: #fff;
        }
    </style>
</head>

<body>

<div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
    <div class="layui-tab-content" style="height: 100%;">
        <div class="layui-tab-item layui-show">
            <div class="layui-container">
                <div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
                    <form:form commandName="subjectActivity" method="post">

                        <form:hidden path="id"/>
                        <input type="hidden" name="_method" value="${_method}">

                        <div class="layui-form-item">
                            <label class="layui-form-label"><span style="color: red;">*</span><fmt:message key='ztlx1'/></label>
                            <div class="layui-input-inline" style="width: 70%">
                                <select name="type.id">
                                    <option value="0"><fmt:message key='qxz'/></option>
                                    <c:forEach var="item" items="${types}">
                                        <option value="${item.id}" <c:if test="${subjectActivity.type.id == item.id}">selected</c:if>>${item.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label"><span style="color: red;">*</span><fmt:message key='ztmc'/></label>
                            <div class="layui-input-inline" style="width: 70%">
                                <form:input class="layui-input" lay-verify="required" path="name"/>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label"><span style="color: red;">*</span><fmt:message key='ztms'/></label>
                            <div class="layui-input-inline" style="width: 70%">
                                <form:input class="layui-input" lay-verify="required" path="description"/>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label"><span style="color: red;">*</span><fmt:message key='ztmb'/></label>
                            <div class="layui-input-inline" style="width: 70%">
                                <input type="button" value="<fmt:message key='scysb'/>" class="layui-btn layui-btn-normal layui-btn-sm upload-zip">
                                <div class="zip-box" style="margin: 6px; padding: 6px;">
                                    <c:if test="${not empty subjectActivity.templateName}">
                                        ${subjectActivity.templateName}<i class="layui-icon layui-icon-delete delete-zip" style="margin-left: 10px; font-weight:bold; cursor: pointer"></i>
                                    </c:if>
                                </div>
                                <form:hidden path="templateName"/>
                                <form:hidden path="templateRealName"/>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label"><span style="color: red;">*</span><fmt:message key='ztal'/></label>
                            <div class="layui-input-inline" style="width: 70%">
                                <a href="${web_domain}/resources/template/template.zip" target="_blank">
                                    <input type="button" value="<fmt:message key='flxz'/>" class="layui-btn layui-btn-normal layui-btn-sm">
                                </a>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label"></label>
                            <div class="layui-input-inline">
                                <input type="button" style="display: none;" value="<fmt:message key='qd1'/>" id="submit" lay-filter="submit" lay-submit class="layui-btn">
                            </div>
                        </div>

                    </form:form>
                </div>
            </div>
        </div>

    </div>
</div>


<div style="display:none;">
    <form action="${web_domain}/upload/zip" method="post" id="upload-zip-form" enctype="multipart/form-data">
        <input class="upload-file" name="file" type="file"/>
    </form>
</div>

<script>

    layui.use(['form'], function () {
        var form = layui.form;
        form.on('submit(submit)', function () {
            $("#subjectActivity").ajaxSubmit({
                success: function (res) {
                    if (res.status) {
                        layer.alert("<fmt:message key='bccg'/>", function () {
                            parent.location.reload();
                        });
                    } else {
                        layer.alert(res.message);
                    }
                }
            });
        });

        $(document).on('click', ".delete-zip", function () {
            $(this).parent().html("");
            $("#templateName").val("");
            $("#templateRealName").val("");
        });

        $(".upload-zip").click(function () {
            $(".upload-file").click();
        });

        $(".upload-file").change(function () {
            $("#upload-zip-form").ajaxSubmit({
                success: function (result) {
                    if (result.status) {
                        $("#templateName").val(result.originalFilename);
                        $("#templateRealName").val(result.filename);
                        $(".zip-box").html(result.originalFilename + ' <i class="layui-icon layui-icon-delete delete-zip" style="margin-left: 10px; font-weight:bold; cursor: pointer"></i>');
                    }
                },
                error: function (result) {
                    console.log(result.responseText);
                }
            });
        });

    });
</script>
</body>
</fmt:bundle>
</html>